<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">


            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">任务名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="search" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">任务类型</label>
                            <div class="layui-input-inline">
                                <select name="task_type" lay-filter="tasktype">
                                    <option value=""></option>
                                    <option value="1">推荐玩家</option>
                                    <option value="2">达成级别</option>
                                    <option value="3">转轮摇奖</option>
                                    <option value="4">金币转账</option>
                                    <option value="5">团队人数</option>
                                    <option value="6">发红包</option>
                                    <option value="7">连续签到</option>
                                    <option value="8">生意出售</option>
                                    <option value="9">生意购买</option>
                                    <option value="10">兑换材料</option>
                                    <option value="11">积分转账</option>
                                    <option value="12">生意交租</option>
                                    <option value="13">激活账号</option>
                                    <option value="14">首次注册</option>
                                    <option value="15">打劫玩家</option>
                                    <option value="16">反击玩家</option>
                                    <option value="17">每日答题</option>
                                    <option value="18">卡券使用</option>
                                    <option value="19">金币充值</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" id="formbutton" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>


        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
{include file="public/footer" /}
<script type="text/html" id="typeTpl">
    {{#  if(d.task_type == 1){ }}
    <span style="color: #f59b28;">推荐玩家</span>
    {{# }else if(d.task_type == 2){ }}
    <span style="color: #f59b28;">达成级别</span>
    {{# }else if(d.task_type == 3){ }}
    <span style="color: #f59b28;">转轮摇奖</span>
    {{# }else if(d.task_type == 4){ }}
    <span style="color: #f59b28;">金币转账</span>
    {{# }else if(d.task_type == 5){ }}
    <span style="color: #f59b28;">团队人数</span>
    {{# }else if(d.task_type == 6){ }}
    <span style="color: #f59b28;">发红包</span>
    {{# }else if(d.task_type == 7){ }}
    <span style="color: #f59b28;">连续签到</span>
    {{# }else if(d.task_type == 8){ }}
    <span style="color: #f59b28;">生意出售</span>
    {{# }else if(d.task_type == 9){ }}
    <span style="color: #f59b28;">生意购买</span>
    {{# }else if(d.task_type == 10){ }}
    <span style="color: #f59b28;">兑换材料</span>
    {{# }else if(d.task_type == 11){ }}
    <span style="color: #f59b28;">积分转账</span>
    {{# }else if(d.task_type == 12){ }}
    <span style="color: #f59b28;">生意交租</span>

    {{# }else if(d.task_type == 13){ }}
    <span style="color: #f59b28;">激活账号</span>
    {{# }else if(d.task_type == 14){ }}
    <span style="color: #f59b28;">首次注册</span>
    {{# }else if(d.task_type == 15){ }}
    <span style="color: #f59b28;">打劫玩家</span>
    {{# }else if(d.task_type == 16){ }}
    <span style="color: #f59b28;">反击玩家</span>
    {{# }else if(d.task_type == 17){ }}
    <span style="color: #f59b28;">每日答题</span>
    {{# }else if(d.task_type == 18){ }}
    <span style="color: #f59b28;">卡券使用</span>
    {{#  } else { }}
    <span style="color:#f59b28;">金币充值</span>
    {{#  } }}
</script>

<script type="text/html" id="levelTpl">
    {{#  if(d.level_limit == 0){ }}
    <span >全部等级</span>
    {{# }else if(d.level_limit == 1){ }}
    <span >1级</span>
    {{# }else if(d.level_limit == 2){ }}
    <span >2级</span>
    {{# }else if(d.level_limit == 3){ }}
    <span >3级</span>
    {{# }else if(d.level_limit == 4){ }}
    <span >4级</span>
    {{# }else if(d.level_limit == 5){ }}
    <span >5级</span>
    {{# }else if(d.level_limit == 6){ }}
    <span >6级</span>
    {{# }else if(d.level_limit == 7){ }}
    <span >7级</span>
    {{# }else if(d.level_limit == 8){ }}
    <span >8级</span>
    {{# }else if(d.level_limit == 9){ }}
    <span >9级</span>
    {{# }else if(d.level_limit == 10){ }}
    <span >10级</span>
    {{# }else if(d.level_limit == 11){ }}
    <span >11级</span>
    {{# }else if(d.level_limit == 12){ }}
    <span >12级</span>
    {{#  } }}
</script>

<script>
    layui.use(['form', 'table','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate=layui.laydate;
        // 上架开始日期
        var insShelf = laydate.render({
            elem: '#start_time'
            , min: 0
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insUnder.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                //insUnder.config.elem[0].focus();
            }
        });
        //上架结束日期
        var insUnder = laydate.render({
            elem: '#end_time'
            , min: 0
            , calendar: true
            , type: 'datetime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                insShelf.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        table.render({
            elem: '#currentTableId',
            url: '/admin/Active/task_index?action=ajax',
            method: 'post',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'task_title', title: '任务名称'},
                {field: 'task_type', title: '任务类型',templet: '#typeTpl'},
                {field: 'task_number', title: '完成数量'},
                {field: 'level_limit', title: '参与等级',templet: '#levelTpl'},
                {field: 'circulation_title', title: '是否循环'},
                {field: 'status_mark', title: '活动状态'},
                {title: '操作', toolbar: '#currentTableBar', minWidth: 120}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'line'
        });
        form.on('select(tasktype)',function(data){
            $("#formbutton").click();
        })
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: data.field
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加任务',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Active/task_add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作


            } else if (obj.event === 'LAYTABLE_TIPS') {
                alert('自定义的,不用的话可以将该方法删除')
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑任务',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Active/task_write?id='+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }else if(obj.event === 'check'){
                var index = layer.open({
                    title: '查看详情',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Active/roulette_static?active_id='+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                var data = obj.data;
                layer.confirm('确定删除吗', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: "/admin/Active/task_delete",
                        type: 'post',
                        async: true,
                        data: {
                            id:data.id
                        },
                        dataType: 'json',
                        success: function (res) {
                            if(res.status){
                                parent.layer.msg("操作成功!", {icon:1,time: 1000}, function () {
                                    //重新加载父页面
                                    obj.del();

                                });
                                return;
                            }else{
                                layer.msg(res.msg);
                            }
                        }
                    });

                });
            }
        });

    });
</script>

</body>
</html>